from datetime import datetime
from pydantic import BaseModel, Field
from typing import Optional, List, Any

class Task(BaseModel):
    id: str
    prompt: str
    created_at: datetime
    status: str
    steps: list = []

    def model_dump(self, *args, **kwargs):
        data = super().model_dump(*args, **kwargs)
        data["created_at"] = self.created_at.isoformat()
        return data
    
class ProxyConfig(BaseModel):
    server: Optional[str] = Field(None, description="代理服务器地址")
    username: Optional[str] = Field(None, description="代理用户名")
    password: Optional[str] = Field(None, description="代理密码")

class BrowserConfig(BaseModel):
    headless: Optional[bool] = Field(False, description="是否启用无头模式")
    disable_security: Optional[bool] = Field(None, description="是否禁用安全功能")
    extra_chromium_args: Optional[List[str]] = Field(None, description="额外的浏览器参数")
    chrome_instance_path: Optional[str] = Field(None, description="Chrome实例路径")
    proxy_enabled:Optional[bool] = Field(False, description="是否启用浏览器代理")
    proxy: Optional[ProxyConfig] = Field(None, description="代理设置")

class LLMConfig(BaseModel):
    model: str = Field(..., description="模型名称")
    base_url: str = Field(..., description="API基础URL")
    api_key: str = Field(..., description="API密钥")
    max_tokens: Optional[int] = Field(None, description="最大令牌数")
    temperature: Optional[float] = Field(None, description="温度")

class SearchConfig(BaseModel):
    engine: Optional[str] = Field(None, description="搜索引擎")
    retry_delay: Optional[int] = Field(None, description="重试延迟")
    max_retries: Optional[int] = Field(None, description="最大重试次数")

class ConfigData(BaseModel):
    llm: Optional[LLMConfig] = Field(None, description="LLM配置")
    browser: Optional[BrowserConfig] = Field(None, description="浏览器配置")
    search: Optional[SearchConfig] = Field(None, description="搜索配置")